/**
 * Created by hjqi on 2016/4/26.
 */
angular.module('NatureCloud').factory('storageService', function ($http) {
    return {
        getStoragelist:function(app){
            /*var _query = "";
            if(app)
                _query = "?app="+app;*/
            return $http.get('/apiStorage/getstorages').then(function (response) {
                return response.data;
            });
        },
        createStorage:function(id,size,date){
            var _data = {
                sid:id,
                size:size,
                date:date
            }
            return $http.post('/apiStorage/createstorage',_data).then(function (response) {
                return response;
            });
        },
        deleteStorage:function(item){
            /*var _data = {
                sid:item.name,
                serviceId:item.svcId
            }*/
            return $http.post('/apiStorage/delstorage',item).then(function (response) {
                return response;
            });
        },
        getFilesFromStorageName:function(id){
            return $http.get('/apiStorage/getfiles?name='+id).then(function (response) {
                return response;
            });
        },
        deleteFiles:function(vol,filename){
            var _data = {
                vol:vol,
                file:filename
            }
            return $http.post('/apiStorage/delfiles',_data).then(function (response) {
                return response;
            });
        },
        uploadfile:function(volumn,formdata){
            var req = {
                method  : 'POST',
                url     : '/apiStorage/uploadfile?sid='+volumn,
                data    : formdata,
                headers : {'Content-Type': undefined }
            }
            return $http(req).then(function (response) {
                return response;
            });
        },
        checkVolumeMgrService:function(volumename){
            var url = '/apiStorage/chkVolMgrSvcExist?name=' +  volumename;
            return $http.get(url).then(function (response) {
                return response;
            });
        },
        createVolumeMgrService:function(volume){
            var _data = {
                volume:volume
            }
            return $http.post('/apiStorage/createVolMgrSvc',_data).then(function (response) {
                return response;
            });
        },
        startVolumeMgrService:function(volumename){
            var _data = {
                action:'start',
                volume:volumename
            }
            return $http.post('/apiStorage/operateVolMgrSvc',_data).then(function (response) {
                return response;
            });
        },
        stopVolumeMgrService:function(volumename){
            var _data = {
                action:'stop',
                volume:volumename
            }
            return $http.post('/apiStorage/operateVolMgrSvc',_data).then(function (response) {
                return response;
            });
        },
        getStorageDetail:function (volumename) {
            return $http.get('/apiStorage/getStorageDetail?name='+volumename).then(function (response) {
               return response.data;
            });
        },
        checkVolumeNameExist:function(volumename){
            return $http.get('/apiStorage/checkVolumeExist?name=' +  volumename).then(function (response) {
                return response;
            });
        }
    };
});